package main

import (
	"fmt"
	ezToken "gitee.com/jinmingzhi/eth-learn/5day/build"
	"gitee.com/jinmingzhi/eth-learn/pkg/ethtool"
	"github.com/ethereum/go-ethereum/accounts/abi/bind"
	"github.com/ethereum/go-ethereum/common"
)

var url = "http://localhost:8545"

func main() {
	client, err := ethtool.Dial(url)
	assert(err)

	contractAddress := common.HexToAddress("0xCfEB869F69431e42cdB54A4F4f105C19C080A601")
	inst, err := ezToken.NewEzToken(contractAddress, client)
	assert(err)
	balance, err := inst.BalanceOf(&bind.CallOpts{
		From: contractAddress,
	},
		common.HexToAddress("0xCfEB869F69431e42cdB54V4F4f105C19C080A601"), // 查的是它的balace
	)

	assert(err)
	fmt.Println("balace:", balance)

	totalSupply, err := inst.TotalSupply(&bind.CallOpts{
		From: contractAddress,
	})
	assert(err)
	fmt.Println("totalSupply:", totalSupply)

}

func assert(err error) {
	if err != nil {
		panic(err)
	}
}
